//
//  PopView.m
//  JiuLe
//
//  Created by xcq on 15/11/10.
//  Copyright © 2015年 Fine. All rights reserved.
//

#import "PopView.h"
#define kMusicTag 0x1
#define kShakeTag 0x2
#define kMusicAndShakeTag 0x3

@implementation PopView

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self == [super initWithCoder:aDecoder]) {

    }
    return self;
}

- (void)viewDidLoad:(int)type {
    _music.userInteractionEnabled = YES;
    _music.tag = kMusicTag;
    _shake.userInteractionEnabled = YES;
    _shake.tag = kShakeTag;
    _musicAndShake.userInteractionEnabled = YES;
    _musicAndShake.tag = kMusicAndShakeTag;
    
    if (type == 1) {
        selectAlarmType = @"响铃";
        [self setAlarmType:kMusicTag];
    } else if (type == 2) {
        selectAlarmType = @"震动";
        [self setAlarmType:kShakeTag];
    } else {
        selectAlarmType = @"响铃+震动";
        [self setAlarmType:kMusicAndShakeTag];
    }
    
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];

    [_music addGestureRecognizer:tap1];
    [_shake addGestureRecognizer:tap2];
    [_musicAndShake addGestureRecognizer:tap];
    
}
- (IBAction)cancelEvent:(id)sender {
    [self removeFromSuperview];
}
- (IBAction)saveEvent:(id)sender {
    if (selectAlarmType == nil || selectAlarmType.length == 0) {
        return;
    }
    _action(selectAlarmType);
    [self cancelEvent:nil];
}

- (void)tapAction:(UIGestureRecognizer *)gesture {
    UIImageView *img = (UIImageView *)gesture.view;
    NSLog(@"%zd",img.tag);
    [self setAlarmType:img.tag];
}

- (void)setAlarmType:(NSInteger)tag {
    if (tag == kMusicTag) {
        selectAlarmType = @"响铃";
        _shake.highlighted = NO;
        _musicAndShake.highlighted = NO;
        _music.highlighted = YES;
    }else if (tag == kShakeTag) {
        selectAlarmType = @"振动";
        _shake.highlighted = YES;
        _musicAndShake.highlighted = NO;
        _music.highlighted = NO;
    } else {
        selectAlarmType = @"响铃+振动";
        _shake.highlighted = NO;
        _musicAndShake.highlighted = YES;
        _music.highlighted = NO;
    }
}

@end
